package com.diver.flinkdemo.mapper.mysqlMapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.diver.flinkdemo.dto.xxt.UserDto;
import com.diver.flinkdemo.entity.xxt.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by wenjun on 2018/7/5.
 */
@Mapper
//@Component
public interface UserMapper extends BaseMapper<User> {

//    @Select("select count(u.id) from user u " +
//            "left join trd_app t on u.account_id = t.account_id " +
//            "left join (select user_id,count(student_card_id) card_count from user_student_card group by user_id) as us on u.id = us.user_id ")
    @Select("SELECT count(id)  FROM user u")
    int queryUserCount();

    @Select("select u.id userId,u.account_id accountId,t.account_name accountName,IFNULL(u.user_name,u.nick_name) nickName,u.telphone,u.id_card idCard,IF(us.card_count>0,1,0) bindingFlag from user u " +
            "left join trd_app t on u.account_id = t.account_id " +
            "left join (select user_id,count(student_card_id) card_count from user_student_card group by user_id) as us on u.id = us.user_id " +
            "limit #{limitStart},#{pageSize}")
    List<UserDto> queryUserList(@Param("limitStart") int limitStart, @Param("pageSize") int pageSize);

    @Select("select account_name from trd_app where account_id = #{accountId}")
    String getChannalName(String accountId);

    @Select("select nick_name from user where id = #{id}")
    String queryNickname(@Param("id") String id);

    @Select("select * from user where open_id = #{openId}")
    User queryByOpenId(String openId);
}
